package com.whoimi.common.jdbc;

/**
 * jdbc 查询条件封装
 *
 * @author whoimi
 * @since 2025-08-01
 **/
public class QueryCondition {
    private String fieldName;
    private SqlOperate.OperateEnum operate;
    private Object value;

    public QueryCondition(String fieldName, SqlOperate.OperateEnum operate, Object value) {
        this.fieldName = fieldName;
        this.operate = operate;
        this.value = value;
    }

    // getters
    public String getFieldName() {
        return fieldName;
    }

    public SqlOperate.OperateEnum getOperate() {
        return operate;
    }

    public Object getValue() {
        return value;
    }

    /**
     * 根据操作符格式化值
     */
    public String formatValue() {
        return switch (operate) {
            case LIKE -> "%" + value.toString() + "%";
            case LIKE_LEFT -> "%" + value.toString();
            case LIKE_RIGHT -> value.toString() + "%";
            default -> value.toString();
        };
    }
}
